<?php

define('IN_PHPBB',   true);
define('BB_ROOT', './');
include(BB_ROOT .'common.php');
include(INC_DIR .'functions_sitemap_fx.php');

$sitemap_config['sitemap_enable'] = true;
$sitemap_config['sitemap_cache_time'] = 60; // minutes
$sitemap_config['sitemap_priority_0'] = '1.0';
$sitemap_config['sitemap_priority_1'] = '0.9';
$sitemap_config['sitemap_priority_2'] = '0.8';
$sitemap_config['sitemap_priority_3'] = '0.7';
$sitemap_config['sitemap_freq_0'] = 'daily';
$sitemap_config['sitemap_freq_1'] = 'daily';
$sitemap_config['sitemap_freq_2'] = 'daily';
$sitemap_config['sitemap_freq_3'] = 'daily';

$sitemap_config['posts_per_page'] = 30;

if (!$sitemap_config['sitemap_enable'])
{
	exit;
}

$url = make_url('/');
$last_forum_id = 0;
$user->session_start();

header("Content-Type: text/xml");

if (!$sitemap_index_file = CACHE('bb_cache')->get("sitemap_fx_index"))
{
	$sitemap_index_file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	$sitemap_index_file .= "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";

	$sql = 'SELECT forum_id, forum_topics'.//, auth_view
		'	FROM ' . BB_FORUMS;
	$result = DB()->query($sql);

	while ($row = DB()->sql_fetchrow($result))
	{
		if ($row['forum_id'] && /*($row['auth_view'] == 1) &&*/ ($row['forum_topics'] > 0))
		{
			sitemap_fx_forum((int) $row['forum_id']);

			$sitemap_index_file .= "<sitemap>\n";
			$sitemap_index_file .= "<loc>" . $url . "sitemap/" . $row['forum_id'] . ".xml</loc>\n";
			$sitemap_index_file .= "<lastmod>" . date('Y-m-d\TH:i:s\Z') . "</lastmod>\n";
			$sitemap_index_file .= "</sitemap>\n";

			$last_forum_id = $row['forum_id'];
		}
	}
	DB()->sql_freeresult($result);

	if(!$bb_cfg['gzip_compress'])
    {
	    flush();
    }

	sitemap_fx_global((int) $last_forum_id);
	$sitemap_index_file .= "<sitemap>\n";
	$sitemap_index_file .= "<loc>" . $url . "sitemap/0.xml</loc>\n";
	$sitemap_index_file .= "<lastmod>" . bb_date(time(), 'c') . "</lastmod>";
	$sitemap_index_file .= "</sitemap>\n";

	$sitemap_index_file .= "</sitemapindex>\n";
	CACHE('bb_cache')->set("sitemap_fx_index", $sitemap_index_file, (60 * $sitemap_config['sitemap_cache_time']));
}

print $sitemap_index_file;

?>